﻿using System.Web.Routing;
using EPiServer.Common.Tags;

namespace JoelAbrahamsson.Web.ExtensionMethods
{
    public static class TagExtensions
    {
        public static string GetUrl(this ITag tag, RequestContext context)
        {
            return "http://"
                + System.Configuration.ConfigurationManager.AppSettings["defaultDomain"]
                + RouteTable.Routes.GetVirtualPath(context, new RouteValueDictionary(new
                {
                    tagName = tag.GetSlug(),
                    controller = "Archive",
                    action = "Tag"
                })
                     ).VirtualPath;
        }

        public static string GetSlug(this ITag tag)
        {
            return tag.Name
                .Replace(" ", "-")
                .Replace("#", "sharp");
        }
    }
}
